var swap = require('array-swap');

var arr = ['apple', 'orange', 'banana', 'pear', 'hello', 'lyy'];
console.log(arr.swap(1, 3));



function test() {
	console.log(arr)
	var ret = arr.splice(3, 1, arr[1])
	arr[1] = ret[0]
	console.log(arr)
	console.log(ret)
}
var arr = ['apple', 'orange', 'banana', 'pear', 'hello', 'lyy'];


var ret = arraySwap(arr, 1, 3)
console.log(ret, ret === arr)


/**
 * 交换数组的元素, 没有考虑边界问题
 * @param  {[type]} arr [description]
 * @param  {[type]} x   [description]
 * @param  {[type]} y   [description]
 * @return {[type]}     [description]
 */
function arraySwap(arr, x, y) {
	var tmp = arr[x]
	arr[x] = arr[y]
	arr[y] = tmp

	return arr;
}



var arr = [1, 3]

